package com.foreknow.demo08;

public class Student {
  int id;
  String name;
  int score;

  public Student(int id,String name,int score) {
    this.id = id;
    this.name = name;
    this.score = score;
  }

  public Student[] getSort(Student[] stu) {
    for(int j = 1;j<stu.length;j++){
      for(int i = 0;i<stu.length-j;i++){
        if(stu[i].score<stu[i+1].score){
          Student temp = stu[i];
          stu[i] = stu[i+1];
          stu[i+1] = temp;
        }
      }
    }
    return stu;
  }

  public static void main(String[] args) {
    Student st1 = new Student(101,"张三",90);
    Student st2 = new Student(102,"李四",80);
    Student st3 = new Student(103,"王五",100);

    Student[] s = {st1,st2,st3}; //向数组中保存元素
    Student[] students = st2.getSort(s);//调用排序的方法
    for(int i = 0;i<students.length;i++){
      Student stu = students[i];
      System.out.println(stu.id+"--"+stu.name+"--"+stu.score);
    }


    //    Student[] ss = new Student[3];
    //
    //    ss[0] = st1;
    //    ss[1] = st2;
    //    ss[2] = st3;
  }

}
